﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExtBusiness.Common;
using ExtBusiness.FlowOperation;
using ExtBusiness;

/// <summary>
/// More 的摘要说明。
/// </summary>
public partial class ManageInside_More : PageBase
{
    ArticleManage amTemp = new ArticleManage();

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            BindType();

            if (Request["action"] == "del")
            {
                string id = Request["id"];
                DataDelete(id);
            }

            BindDG();
        }
    }

    private void BindType()
    {
        DataTable dtSource = amTemp.GetBigType();
             
        ddlType.Items.Clear();
        ddlType.Items.Add("");
        for (int i = 0; i < dtSource.Rows.Count; i++)
        {
            ddlType.Items.Add(dtSource.Rows[i]["type"].ToString());
        }
    }

    /// <summary>
    /// 绑定
    /// </summary>
    private void BindDG()
    {
        string strWhere = string.Empty;

        if (!string.IsNullOrEmpty(Request["type"]))
        {
            strWhere += string.Format(" and t.type='{0}'", Request["type"]);
        }
        else if (!string.IsNullOrEmpty(ddlType.Text))
        {
            strWhere += string.Format(" and t.type='{0}'", ddlType.Text);
        }

        if (!string.IsNullOrEmpty(Request["datatype"]))
        {
            strWhere += string.Format(" and smalltype='{0}'", Request["datatype"]);
        }
        

        DataTable dtSource = amTemp.GetAllAiticle(strWhere);
        if (dtSource != null)
        {
            dgInfo.DataSource = dtSource;
            dgInfo.RecordCount = dtSource.Rows.Count;
            dgInfo.DataBind();
        }
    }

    protected void DataDelete(string id)
    {
        if (!string.IsNullOrEmpty(id))
        {
            amTemp.DeleteArticle(id);
        }
        else
        {
            Response.Write("<script>alert('删除失败');</script>");
        }
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dgInfo_OnLoadData(object sender, EventArgs e)
    {
        BindDG();
    }

    /// <summary>
    /// 数据列创建事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dgInfo_RowCreated(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.Header:
                break;
            case DataControlRowType.DataRow:
                {
                    DataRowView dRowView = (DataRowView)e.Row.DataItem;
                    if (dRowView != null)
                    {
                        string strUrl = string.Empty;

                        String id = dRowView["ID"].ToString();

                        HyperLink hylkDel = e.Row.FindControl("hldel") as HyperLink;
                        hylkDel.NavigateUrl = string.Format("More.aspx?id={0}&action=del&type={1}",id,Request["type"]);
                        hylkDel.Visible = true;
                        HyperLink hylkmodify = e.Row.FindControl("hlmodify") as HyperLink;

                        hylkmodify.NavigateUrl = string.Format("webpubmanager.aspx?id={0}&action=modify&type={1}", id, Request["type"]); 
                        hylkmodify.Visible = true;

                        HyperLink Viewstatus = e.Row.FindControl("Viewstatus") as HyperLink;
                        Viewstatus.NavigateUrl = string.Format("sendlisthistory.aspx?id={0}",id);
                        Viewstatus.Visible = true;
                    }
                    break;
                }
        }
    }

    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindDG();
    }
}